import { Injectable } from '@nestjs/common';
import { Workbook } from 'exceljs';

@Injectable()
export class ExcelService {
  async exportExcel(colunms: unknown[], data: unknown[], sheetName: string) {
    const workBook = new Workbook();
    const sheet = workBook.addWorksheet(sheetName);
    sheet.columns = colunms;
    data.forEach((row) => {
      sheet.addRow(row);
    });

    return await workBook.xlsx.writeBuffer();
  }
}
